/* 
** test cast/sizeof
*/
#include <stdio.h>
#include <string.h>

static char * lcs_logname = "lcs_cast_sizeof";
static char lcs_logbuf[512];

static void lcs_testlog()
{
	int fp;
	
	fp = fopen( lcs_logname, "at" );
	if( !fp ) return;

	printf( "%s", lcs_logbuf );
	fprintf( fp, "%s", lcs_logbuf );
	
	fclose( fp );
}

/*
** test begin...
*/
#pragma pack(1)

int lcs_cast_sizeof()
{
	struct _cs{
		char c;
		int i;
		float f;
		char buf[50];
	};
	char buf[128] = "here is a test of cast string";
	struct _cs * p = (struct _cs *)buf;

	int x, n = 613;
	float ft = 1.2;
	double db = 3.4;
	
	db++;
	--db;

	x = (int)db;

	sprintf( lcs_logbuf, "%c, %i, %f, %s\n", (struct _cs *)p->c, p->i, p->f, p->buf );
	lcs_testlog();
	sprintf( lcs_logbuf, "%c, %i, %f, %s\n", ((struct _cs *)buf)->c, ((struct _cs *)buf)->i, ((struct _cs *)buf)->f, ((struct _cs *)buf)->buf );
	lcs_testlog();

	sprintf( lcs_logbuf, "%d, %f, %f, %f, %d, %d, %d\n", n, ft, db, (float)n, (int)ft, (int)db, x );
	lcs_testlog();

	sprintf( lcs_logbuf, "%d, %d, %d, %d, %d\n", 
		sizeof(n), sizeof n, sizeof buf, sizeof(struct _cs), sizeof ((struct _cs *)buf)->buf );
	lcs_testlog();
	
	return 0;
}

#pragma pack()
